package org.luxor.common.netty.protocol;

import io.netty.util.internal.StringUtil;
import org.springframework.util.StringUtils;

import java.nio.charset.StandardCharsets;

/**
 * Netty Request VariableHeader
 *
 * @author Mr.yan @date 2024/1/31
 */
public class NettySendVariableHeader extends NettyMessageIdVariableHeader {
    private final String messageName;
    private final String accessToken;
    private final String contentType;

    public NettySendVariableHeader(String messageId, String messageName, String accessToken) {
        super(messageId);
        if (!StringUtils.hasText(messageName)) {
            throw new IllegalArgumentException("messageName is not null");
        }
        this.messageName = messageName;
        this.accessToken = accessToken;
        this.contentType = NettyContentType.JSON.toString(StandardCharsets.UTF_8);
    }

    public NettySendVariableHeader(String messageId, String messageName) {
        this(messageId, messageName, null);
    }

    public String messageName() {
        return this.messageName;
    }

    public String accessToken() {
        return this.accessToken;
    }

    public String contentType() {
        return this.contentType;
    }

    public static NettySendVariableHeader from(String messageId, String messageName, String accessToken) {
        return new NettySendVariableHeader(messageId, messageName, accessToken);
    }

    public static NettySendVariableHeader from(String messageId, String messageName) {
        return from(messageId, messageName, null);
    }

    @Override
    public String toString() {
        return StringUtil.simpleClassName(this) +
                '[' +
                "messageId=" + super.messageId() +
                ", messageName=" + messageName +
                ", accessToken=" + accessToken +
                ", contentType=" + contentType +
                ']';
    }
}
